<?php
/**
 * Created by PhpStorm.
 * User: linyh
 * Date: 2017/11/25 0025 10:13
 */
?>
<!-- Content Header (Page header) -->
<section class="content-header" style="text-align: center">
    <h1 class="page-header" style="font-size: 2.3em;"></h1>
    <h4><i class="fa fa-calendar"></i>  <span id="time"></span>  &nbsp;&nbsp;&nbsp;&nbsp;<i class="fa fa-user"></i>  by  <span id="author"></span></h4>
</section>
<!-- Main content -->
<!--配方提交-->
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <!-- 配方提交 -->
            <div class="box">
                <div class="box-body">
                    <article></article>
                    <div class="box-footer" style="text-align: center;background-color:transparent;border-top:hidden;">
                        <button id="content_back" type="button" class="btn btn-success">返回</button>
                    </div>
                </div>
            </div>
            <!-- /.box -->
        </div>
    </div>
</section>

<script>
var $table = $('table');
var $tr = $table.find('tbody tr').remove();
$.ajax('/api/news/get', {
    type: 'GET',
    data: {
        'id': $.query2object().id,
    },
    dataType: 'json',
    headers: {'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest'}
}).then(function(ret) {
    if(ret.state == 0) {
        var data = ret.data;
        var news = data.news;
        console.log(data);
        $('h1').text(news.title);
        $('#time').text(news.time);
        $('#author').text(news.author.username);
        $('article').html(news.content);
        if(news.type == 2){
            $("#content_back").click(function () {
                location.href = '/news/notice'
            })
        }else{
            $("#content_back").click(function () {
                location.href = '/news/index'
            })
        }
    } else {
        alert(ret.message);
    }
});
</script>